package dto;
// Generated Mar 20, 2013 5:08:51 PM by Hibernate Tools 3.2.1.GA

import dto_pakinfo.User;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Order generated by hbm2java
 */
@Entity
@Table(name = "[Order]", schema = "dbo", catalog = "AntiqueShop")
@XmlRootElement
public class Order implements java.io.Serializable {

    @XmlAttribute(name = "id", required = true)
    private int id;
    @XmlElement(name = "user", required = true)
    private User user;
    @XmlElement(name = "orderstatus", required = true)
    private OrderStatus orderStatus;
    @XmlElement(name = "placedDate", required = true)
    private Date placedDatetime;
    @XmlElement(name = "deliveredDate", required = false)
    private Date deliveredDatetime;
    @XmlElement(name = "charges", required = true)
    private double shippingCharges;
    @XmlElement(name = "updateDate", required = false)
    private Date updateDate;
    @XmlElement(name = "deleted", required = true)
    private boolean isDeleted;
    @XmlAttribute(name = "confirmation", required = true)
    private String confirmationString;
    @XmlElement(name = "note", required = false)
    private String note;
    @XmlElementWrapper(name = "orderitemses", required = true)
    @XmlElement(name = "orderitems", required = true)
    private List<OrderItems> orderItemses = new ArrayList<OrderItems>();
    @XmlElement(name = "subAmount", required = true)
    private double subAmount;

    public Order() {
        this.placedDatetime = new Date();
        this.updateDate = new Date();
        this.confirmationString = String.valueOf((new Date().getTime()));
        this.shippingCharges = 0;
        this.isDeleted = false;
    }

    public Order(int id, User user, OrderStatus orderStatus, Date placedDatetime, Date deliveredDatetime, double shippingCharges, boolean isDeleted, String confirmationString, double subAmount) {
        this.id = id;
        this.user = user;
        this.orderStatus = orderStatus;
        this.placedDatetime = placedDatetime;
        this.deliveredDatetime = deliveredDatetime;
        this.shippingCharges = shippingCharges;
        this.isDeleted = isDeleted;
        this.confirmationString = confirmationString;
        this.subAmount = subAmount;
    }

    public Order(int id, User user, OrderStatus orderStatus, Date placedDatetime, Date deliveredDatetime, double shippingCharges, Date updateDate, boolean isDeleted, String confirmationString, String note, List<OrderItems> orderItemses, double subAmount) {
        this.id = id;
        this.user = user;
        this.orderStatus = orderStatus;
        this.placedDatetime = placedDatetime;
        this.deliveredDatetime = deliveredDatetime;
        this.shippingCharges = shippingCharges;
        this.updateDate = updateDate;
        this.isDeleted = isDeleted;
        this.confirmationString = confirmationString;
        this.note = note;
        this.orderItemses = orderItemses;
        this.subAmount = subAmount;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "customer_id", nullable = false)
    public User getUser() {
        return this.user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "order_status_id", nullable = false)
    public OrderStatus getOrderStatus() {
        return this.orderStatus;
    }

    public void setOrderStatus(OrderStatus orderStatus) {
        this.orderStatus = orderStatus;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "placed_datetime", nullable = false, length = 23)
    public Date getPlacedDatetime() {
        return this.placedDatetime;
    }

    public void setPlacedDatetime(Date placedDatetime) {
        this.placedDatetime = placedDatetime;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "delivered_datetime", nullable = true, length = 23)
    public Date getDeliveredDatetime() {
        return this.deliveredDatetime;
    }

    public void setDeliveredDatetime(Date deliveredDatetime) {
        this.deliveredDatetime = deliveredDatetime;
    }

    @Column(name = "shipping_charges", nullable = false, precision = 53, scale = 0)
    public double getShippingCharges() {
        return this.shippingCharges;
    }

    public void setShippingCharges(double shippingCharges) {
        this.shippingCharges = shippingCharges;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "update_date", length = 23)
    public Date getUpdateDate() {
        return this.updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @Column(name = "is_deleted", nullable = false)
    public boolean isIsDeleted() {
        return this.isDeleted;
    }

    public void setIsDeleted(boolean isDeleted) {
        this.isDeleted = isDeleted;
    }

    @Column(name = "confirmation_string", nullable = false)
    public String getConfirmationString() {
        return this.confirmationString;
    }

    public void setConfirmationString(String confirmationString) {
        this.confirmationString = confirmationString;
    }

    @Column(name = "note")
    public String getNote() {
        return this.note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "order")
    public List<OrderItems> getOrderItemses() {
        return this.orderItemses;
    }

    public void setOrderItemses(List<OrderItems> orderItemses) {
        this.orderItemses = orderItemses;
    }

    @Column(name = "subAmount")
    public double getSubAmount() {
//        OrderDAO dao = new OrderDAO(Order.class);
//        dao.openSession();
//        subAmount = dao.calculateOrderTotal(this.id);
//        dao.closeSession();
        return subAmount;
    }

    /**
     * @param subAmount the subAmount to set
     */
    public void setSubAmount(double subAmount) {
        this.subAmount = subAmount;
    }
}
